
package jpoco.test;

import jpoco.client.*;
import jpoco.client.Response.*;
import junit.framework.TestCase;
import java.util.*;


public abstract class AbstractTestCase extends TestCase
{
	static
	{
		System.getProperties().put("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
		System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "trace");
	}
	
	public void assertValid(MultipleContactResponse r) throws Exception
	{
		
		assertNotNull(r);
		
		assertNotNull(r.getContacts());
		
		assertTrue(r.getContacts().size() >= 0);
		
		for ( Contact c : r.getContacts() )
		{
			assertNotNull(c.toString());
			assertNotNull(c.getId());
			assertAccountList(c.getAccounts());
			assertNotNull(c.getEmails());
		}
		
	}
	
	public void assertAccountList(List<Account> accounts)
	{
		assertNotNull(accounts);
		
		for (Account a : accounts)
		{
			assertValid(a);
		}
	}
	
	public void assertValid(Account a)
	{
		assertNotNull(a);
		assertNotNull(a.getUsername());
		assertNotNull(a.getDomain());
	}

	protected void assertContactList(List<Contact> contacts)
	{
		assertNotNull(contacts);
		
		for (Contact c : contacts)
		{
			assertValid(c);
		}
	}
	
	protected void assertValid(Contact c)
	{
		assertNotNull(c);
		// todo (?) assertNotNull(c.getId());
		assertNotNull(c.getEmails());
		assertNotNull(c.getPhotos());
		assertNotNull(c.getAddresses());
		assertNotNull(c.getAccounts());
		assertNotNull(c.getRelationships());
		assertNotNull(c.getInstantMessagingAddresses());
		assertNotNull(c.getTags());
	}

	protected void assertEquals(MultipleContactResponse r1, MultipleContactResponse r2)
	{
		if (r1.getContacts().size() != r2.getContacts().size())
		{
			fail("contact list sizes are different");
		}

		for (int i = 0; i < r1.getContacts().size(); i++)
		{
			assertEquals(r1.getContacts().get(i), r1.getContacts().get(i));
		}
	}
	
	protected void assertEquals(Contact c1, Contact c2)
	{
		assertEquals(c1.getId(), c2.getId());
		assertEquals(c1.getName(), c2.getName());
		assertEquals(c1.getDisplayName(), c2.getDisplayName());
	}
}
